package com.naiterui.ehp.bs.recommend.controller.inner;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.recommend.service.IRecomSuperviseService;
import com.naiterui.ehp.bs.recommend.vo.PrescriptionVO;
import com.naiterui.ehp.bs.recommend.vo.SuperviseRecomVO;
import com.naiterui.ehp.bs.recommend.vo.TianjinSuperviseRecomVO;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * <pre>
 * 提供监管对接信息获取内部接口
 * </pre>
 *
 * @author fangguanhong
 * @date 2021/1/13 下午1:47
 * @since 1.0.0
 */
@Slf4j
@RequestMapping("recommend/inner/supervise/recom")
@RestController
public class InnerRecomSuperviseController {

    @Autowired
    private IRecomSuperviseService recomSuperviseService;

    /**
     * 获取会话相关处方信息
     *
     * @param sessionId
     *
     * @return
     */
    @GetMapping("get")
    public ResponseVO<List<SuperviseRecomVO>> sessionRecoms(Long sessionId) {
        return PublicService.returnResponseVO(recomSuperviseService.sessionRecoms(sessionId));
    }

    /**
     * 获取处方签名文件信息
     *
     * @param sessionId
     *
     * @return
     */
    @GetMapping("prescription")
    public ResponseVO<PrescriptionVO> getPrescription(Long sessionId) {
        return PublicService.returnResponseVO(recomSuperviseService.getPrescription(sessionId));
    }

    /**
     * 天津处方信息
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @GetMapping("tianjin/recom/list")
    public ResponseVO<List<TianjinSuperviseRecomVO>> tianjinRecomList(String startDate, String endDate)
        throws BusinessException {
        log.info("获取天津处方信息 startDate:{}, endDate:{}", startDate, endDate);
        Date start = DateUtil.parseDateTime(startDate).toJdkDate();
        Date end = DateUtil.parseDateTime(endDate).toJdkDate();
        return PublicService.returnResponseVO(recomSuperviseService.tianjinRecomList(start, end));
    }

    /**
     * 处方诊断信息
     *
     * @param sessionIds
     * @return
     */
    @PostMapping("diagnosis")
    public ResponseVO<Map<Long, Set<String>>> recomDiagnosis(String sessionIds, String recomIds) {
        return PublicService.returnResponseVO(recomSuperviseService.recomDiagnosis(sessionIds, recomIds));
    }
}
